<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Accepter Chat Example</title>
    <script src="./jquery-1.12.1.js"></script>
    <script src="./socket.io.js"></script>
    <script>
        $(document).ready(function(){
            var command = {
                "command":"queryMessage",
                "version":"1.0",
                "id":"b5265010-bb7a-11e6-a60f-77d95c87b19f",
                "data" :{
                    "filters":{
                        "type":"group",
                        "read":"*",
                        "accepter":"zzgghh",
                        "topics":["topic5"],
                        "groupId":"1"
                    },
                    "options":{
                        "noContent":"false",
                        "paginate":{
                            "pageSize":"10",
                            "page":"0"
                        }
                    }
                }
            }
			var loginCommand = {
				"command": "login",
				"version":"0.1",
				"id":"b5265010-bb7a-11e6-a60f-77d95c87b193",
				"data":{
				  "userName":"77777",
				  "password":"33333333",//如果支持其他登录方式，这里的信息可能是其他的
				  "loginType":"dependency",//dependency|singleton  用户单独登录，或者依赖客户端登录
				  "clientNature":"enzyme"//可选参数，用户在依赖模式登录下必填
				}
			}
            var ws = new WebSocket("ws://10.2.9.19:8284/msg");
            ws.onopen = WSonOpen;
            ws.onmessage = WSonMessage;
            ws.onclose = WSonClose;
            ws.onerror = WSonError;

            function WSonOpen() {
                Log("连接已经建立。", "OK");
                $("#message").append("<h4>初始化：</h4>");
                ws.send(JSON.stringify(loginCommand));
                //ws.send('{"groupInit":"group-1"}');
                /*var wsc = new WebSocket("ws://10.2.9.19:8285/client");
                wsc.onopen = function() {
                    var str = JSON.stringify(command);
                    wsc.send(str);
                }
                wsc.onmessage = function WSonMessage(event) {
                    $("#message").append("<h4>来自群组1的消息："+event.data+"</h4>");
                    Log(event.data);
                };*/
            };

            function WSonMessage(event) {
                $("#message").append("<h4>来自服务端消息："+event.data+"</h4>");
                Log(event.data);
            };

            function WSonClose() {
                Log("连接关闭。", "ERROR");
            };


            function WSonError() {
                Log("WebSocket错误。", "ERROR");
            };

            function Log(mes){
                console.log(mes);
            }
            $("#send").click(function(){
                ws.send({"userInit":"enzyme"});
            });
			
			/*var ws1 = new WebSocket("ws://10.2.9.19:8284/user");
            ws1.onopen = WSonOpen1;
            ws1.onmessage = WSonMessage1;
            ws1.onclose = WSonClose1;
            ws1.onerror = WSonError1;

            function WSonOpen1() {
                Log("连接已经建立。", "OK");
                $("#message").append("<h4>初始化：</h4>");
                ws1.send('{"userInit":"enzyme-zzgghh1"}');
            };

            function WSonMessage1(event) {
                $("#message").append("<h4>来自服务端消息1111："+event.data+"</h4>");
                Log(event.data);
            };

            function WSonClose1() {
                Log("连接关闭。", "ERROR");
            };

            function WSonError1() {
                Log("WebSocket错误。", "ERROR");
            };*/
        });
    </script>
</head>
<body>
<div id="message">

</div>
</body>
</html>